﻿#if !WINDOWS_PHONE
using System;
using Ops.Mpc.States;
using Ops.Mpc.Collections;
using Ops.Mpc.Events;

namespace Ops.Mpc.Models
{
    public class PagerModel<ModelType, ItemType> : Model<ModelType>
        where ItemType : class
        where ModelType : PagerModel<ModelType, ItemType>
    {
        #region Fields & Properties
        private PagerView<ItemType> _items;

        public PagerView<ItemType> Items
        {
            get
            {
                return _items;
            }

            set
            {
                this._items = value;
                this.RaisePropertyChanged(m=>m.Items);
            }
        }

        public GetPageAction GetPageAction
        {
            get;
            set;
        }
        #endregion

        #region Constructors
        public PagerModel()
        {
        }
        #endregion

        #region Methods
        public override void Start()
        {
            base.Start();

            this.Items = new PagerView<ItemType>();
            this.Items.GetPageRequest += OnGetPageRequest;

            if (this.GetPageAction != null)
            {
                this.GetPageAction.Controller = this.Controller;
                this.GetPageAction.Start();
            }

        }

        public virtual void Clear()
        {
            this.Items.Reset();
        }

        private void OnGetPageRequest(object sender, PagerEventArgs e)
        {
            if(this.GetPageAction != null)
                this.GetPageAction.Execute(e, new ActionResultCallback(OnGetPageRequestComplete));
        }

        protected virtual void OnGetPageRequestComplete(ActionResult actionResult)
        {

        }


        #endregion







    }
}
#endif